package com.xianggu.mybatis.headlerImpl;

import com.xianggu.mybatis.utils.TypeHandler;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author chengjy
 * @date 2025/3/5
 */
public class BigDecimalTypeHandler implements TypeHandler<BigDecimal> {
    @Override
    public void setPreparedStatementValue(PreparedStatement preparedStatement, int i, BigDecimal s, String pName) {
        try {
            preparedStatement.setBigDecimal(i , s);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public BigDecimal getParameterValue(ResultSet resultSet, String columnName) {
        try {
            return resultSet.getBigDecimal( columnName);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public BigDecimal toBaseType(Object i) {
        return new BigDecimal(String.valueOf(i));
    }
}
